<template xmlns:v-on="http://www.w3.org/1999/xhtml">
  <div class="content">
      <!-- 头部 -->
    <div class="main-title">
      <ul>
        <li>
          <div @click="navBackClick(1)" class="main-title-left main-title-noSelect">
            首页
          </div>
          <div class="main-title-right">
            /
          </div>
        </li>
        <li>
          <div @click="navBackClick(1)" class="main-title-left main-title-noSelect">
            系统设置
          </div>
          <div class="main-title-right">
            /
          </div>
        </li>
        <li>
          <div @click="navBackClick(2)" class="main-title-left main-title-noSelect">
            账户管理
          </div>
          <div class="main-title-right">
            /
          </div>
        </li>
        <li>
          <div class="main-title-left main-title-select">
            {{navNameVal}}
          </div>
          <div class="main-title-right">
            <!-- / -->
          </div>
        </li>
      </ul>
    </div>
    <div class="content-center">
      <!--筛选-->
      <!-- <div class="main-search">
      </div> -->
      <!--列表-->
      <div class="main-list">
        <div class="list-two">
          <div class="list-two-list">
            <div>昵称</div>
            <div>
              <input type="text" v-model="nameVal">                
            </div>
          </div>
          <div class="list-two-list">
            <!-- <div>账户</div>
            <div>    
                <input type="text" v-model="usernameVal">           
            </div> -->
          </div>
        </div>
        <div class="list-two">
          <div class="list-two-list">
            <div>账户</div>
            <div>    
                <input type="text" v-model="usernameVal">           
            </div>
          </div>
          <div class="list-two-list">
            <div></div>
            <div>           
            </div>
          </div>
        </div>
        <div class="list-two" v-show="updateShow">
          <div class="list-two-list">
            <div>密码</div>
            <div>
              <input type="text"  v-model="passwordVal">          
            </div>
          </div>
          <div class="list-two-list">
            <div></div>
            <div>           
            </div>
          </div>
        </div>

        <!-- <div class="list-text">
          <div>备注</div>
          <div>
            <textarea></textarea>                
          </div>
        </div> -->
        <div class="list-button">
          <div class="button-save" @click="addClick">
            保&nbsp;&nbsp;存
          </div>
          <div class="button-cancel" @click="backClick">
            取&nbsp;&nbsp;消
          </div>
        </div>
      </div>
      <div :class="{showdel:isShowdel}" class="delPopup">
        <transition name="slide-fade">
          <div class="delContent">
            <v-mIntercept @ok="confirmClick" @canle="cancelClick" :name="titlename"></v-mIntercept>
          </div>
        </transition>
      </div>
    </div>
  </div>
</template>
<script>
import { mapActions } from "vuex";
import mIntercept from "../module/mIntercept";
export default {
  components: {
    "v-mIntercept": mIntercept
  },
  data() {
    return {
      updateShow: true,
      type: "0",
      types: [{ name: "全部标签" }, { name: "标签1" }],
      isShowdel: true,
      intercept: false,
      toPath: "",
      titlename: "劳动成果还未保存，是否退出？",
      pageSizeNum: 10,
      currentPage: 1,
      totalNum: 0,
      usernameVal: "",
      passwordVal: "",
      nameVal: "",
      navNameVal: ""
    };
  },
  // 过滤
  filters: {},
  // 模块新建时
  created: function() {
    var self = this;
    if (self.$route.query.op == 2) {
      var accountObj = JSON.parse(sessionStorage.getItem("accountListObj"));
      self.usernameVal = accountObj.username;
      self.passwordVal = accountObj.password;
      self.nameVal = accountObj.name || "";
      self.updateShow = false;
      self.navNameVal = "修改账户";
    } else {
      self.updateShow = true;
      self.navNameVal = "新增账户";
    }
  },
  // 计算属性
  mounted() {},
  // 事件处理
  methods: {
    // 面包屑返回
    navBackClick(index) {
      if (index == 2) {
        this.$router.push({
          path: "/home/account"
        });
      } else if (index == 1) {
        this.$router.push({
          path: "/home/system"
        });
      }
    },
    backClick() {
      this.$router.push({
        path: "/home/account"
      });
    },
    addClick() {
      var self = this;
      var obj = {};
      if (self.nameVal.length > 0) {
        obj = {
          username: self.usernameVal,
          password: self.passwordVal,
          name: self.nameVal
        };
      } else {
        obj = {
          username: self.usernameVal,
          password: self.passwordVal
        };
      }
      if (self.$route.query.op == 2) {
        obj["id"] = self.$route.query.id;
      }

      var vFunFalse = self.vFun();
      if (vFunFalse == true) {
        self
          .getuser(obj)
          .then(data => {
            if (data.code == 200) {
              this.$router.push({
                path: "/home/account"
              });
            } else {
              self.$message({
                type: "info",
                message: data.message
              });
            }
          })
          .catch(msg => {
            this.$router.push({
              path: "/login"
            });
            self.$message({
              type: "info",
              message: "服务器异常!"
            });
          });
      }
    },
    vFun() {
      var self = this;
      var phoneReg = new RegExp(/^\d{11}$/);
      var numReg = new RegExp(/^\d{1,17}$/);
      var emailReg = new RegExp(
        /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/
      );
      var azReg = new RegExp(/^[a-zA-Z0-9]{5,15}$/);
      var strReg = new RegExp(/^[\u4e00-\u9fa5]{2,10}$/);
      var vFunFalse = false;
      if (self.$route.query.op == 2) {
        if (azReg.test(self.usernameVal) == true) {
          vFunFalse = true;
        } else {
          self.$message({
            type: "info",
            message: "账号必填且为字母"
          });
          vFunFalse = false;
        }
      } else {
        if (azReg.test(self.usernameVal) == true) {
          if (azReg.test(self.passwordVal) == true) {
            vFunFalse = true;
          } else {
            self.$message({
              type: "info",
              message: "密码为字母与数字组合"
            });
            vFunFalse = false;
          }
        } else {
          self.$message({
            type: "info",
            message: "账号为字母与数字组合"
          });
          vFunFalse = false;
        }
      }

      return vFunFalse;
    },
    selectTypesClick() {},
    confirmClick() {
      this.intercept = true;
      var url = this.toPath;
      this.$router.push({
        path: url
      });
    },
    //取消未保存弹出框
    cancelClick() {
      this.isShowdel = true;
    },
    ...mapActions(["getuser"])
  },
  // 监视
  watch: {}
};
</script>
<style scoped>
.button-save {
  margin-left: 108px;
  width: 74px;
  height: 32px;
  border-radius: 4px;
  background-color: rgba(250, 140, 22, 1);
  text-align: center;
  line-height: 32px;
  color: #fff;
  cursor: pointer;
  font-size: 14px;
  color: rgba(255, 255, 255, 1);
}
.button-cancel {
  cursor: pointer;
  margin-left: 18px;
  width: 74px;
  height: 32px;
  border: 1px solid #ffd9d9d9;
  text-align: center;
  line-height: 32px;
  font-size: 14px;
  border-radius: 4px;
  background-color: #fff;
  color: rgba(0, 0, 0, 0.65);
}
.list-button {
  margin-top: 45px;
  width: 500px;
  display: flex;
}
.list-file-r-file label {
  border-radius: 4px;
  min-width: 120px;
  height: 30px;
  background-color: #2fa89e;
  display: flex;
  align-items: center;
  justify-content: space-around;
  font-size: 14px;
  color: #fff;
  cursor: pointer;
}
.list-file-r-file label img {
  width: 20px;
  height: 20px;
}
.list-file-r-file input {
  opacity: 0;
}
.list-file-r-file {
  min-width: 110px;
  height: 28px;
  margin-left: 25px;
  display: flex;
}
.list-file-r-img {
  width: 110px;
  height: 50px;
  border: 1px solid #ccc;
}
.list-file-right {
  width: 500px;
  height: 50px;
  margin-left: 15px;
  display: flex;
  align-items: center;
}
.list-file {
  display: flex;
  height: 70px;
  margin-top: 18px;
  width: 100%;
}

.list-file > div:nth-child(1) {
  width: 150px;
  font-size: 15px;
  font-weight: 600;
  color: #666;
  text-align: right;
}
.list-text {
  display: flex;
  height: 70px;
  width: 100%;
}

.list-text > div:nth-child(1) {
  width: 150px;
  font-size: 15px;
  font-weight: 600;
  color: #666;
  text-align: right;
}
.list-text > div:nth-child(2) textarea {
  width: 560px;
  resize: none;
  height: 65px;
  border: 1px solid #ccc;
  border-radius: 4px;
}
.list-text > div:nth-child(2) {
  margin-left: 15px;
  min-width: 540px;
  height: 65px;
}

.list-two-list {
  display: flex;
  width: 50%;
  align-items: center;
}
.list-two-list > div:nth-child(1) {
  width: 93px;
  font-size: 14px;
  color: rgba(0, 0, 0, 0.65);
  text-align: right;
}
.list-two-list > div:nth-child(2) {
  margin-left: 15px;
  width: calc(100% - 118px);
  /* border: 1px solid red; */
  color: rgba(0, 0, 0, 0.65);
  font-size: 14px;
}
.list-two-list > div:nth-child(2) input {
  width: 94%;
}
.list-two-list > div:nth-child(2) select {
  width: calc(94% + 7px);
}
.list-two > div:nth-child(2) {
  margin-left: 15px;
}

.list-two {
  display: flex;
  align-items: center;
  height: 32px;
  margin-top: 35px;
}

select {
  width: 207px;
  height: 32px;
  border-radius: 4px;
  line-height: 32px;
  color: rgba(0, 0, 0, 0.65);
  border: 1px solid #ffd7d7d7;
  padding-left: 3px;
  font-size: 14px;
}
input {
  width: 200px;
  height: 32px;
  border-radius: 4px;
  line-height: 32px;
  color: rgba(0, 0, 0, 0.65);
  border: 1px solid #ffd7d7d7;
  padding-left: 7px;
  font-size: 14px;
}
select::-ms-expand,
select::-webkit-expand {
  display: none;
}
.main-list > div {
  width: 100%;
  min-height: 32px;
}
.main-list {
  width: 100%;
  margin-top: 15px;
  min-height: 50px;
  background-color: #ffff;
  min-height: 500px;
}

.main-title-noSelect {
  font-size: 14px;
  color: rgba(0, 0, 0, 0.65);
  cursor: pointer;
}
.main-title-select {
  font-size: 14px;
  color: rgba(0, 0, 0, 0.85);
  font-weight: 600;
}

.main-title-right {
  width: 23px;
  text-align: center;
  font-size: 14px;
  color: rgba(0, 0, 0, 0.65);
}

.main-title ul {
  width: 100%;
  display: flex;
  height: 54px;
  margin-left: 34px;
}
.main-title ul li {
  display: flex;
}
.main-title {
  width: 100%;
  height: 54px;
  background-color: #fff;
  line-height: 54px;
  overflow: hidden;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: inset 0px 3px 3px 0px #ccc;
}
.content {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: rgba(240, 242, 245, 1) !important;
  min-height: 720px;
  /* border: 1px solid red; */
  display: flex;
  flex-wrap: wrap;
}

.content-center {
  overflow: hidden;
  width: calc(100% - 48px);
  margin-left: 24px;
  background-color: #fff;
  margin-top: 24px;
  border-radius: 3px;
  min-height: calc(100% - 78px - 24px);
  margin-bottom: 24px;
}

/*取消弹出框*/

.delPopup {
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0);
  z-index: 1000000;
}

.showdel {
  display: none;
}

.delContent {
  width: 525px;
  height: 280px;
  background-color: #fff;
  border: 1px solid #eaeaea;
  box-shadow: 0px 10px 10px #eaeaea;
  border-radius: 7px;
  margin: calc((100vh - 280px) / 2) auto;
  z-index: 100000;
}

.slide-fade-enter-active {
  transition: all 0.7s ease;
}

.slide-fade-enter,
.slide-fade-leave-active {
  transform: translateY(-30px);
  opacity: 0;
}
</style>